<?php
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
?>
<div class="row-fluid">
    <div class="box span12">
        <div class="box-header">
            <h2><i class="icon-edit"></i>Hotdeal</h2>
            <div class="box-icon">
                <a href="<?php echo Yii::app()->createUrl('hotdeal/list') ?>" class=""><i class="icon-arrow-left"></i></a>
            </div>
        </div>
        <div class="box-content">
            <?php
            $form = $this->beginWidget('CActiveForm', array(
                'id'                   => 'Hotdeal',
                'enableAjaxValidation' => true,
//                'enableClientValidation' => true,
                'htmlOptions'          => array(
                    'class' => 'form-horizontal',
                ),
            ));
            ?>
            <fieldset>
                <div class="control-group">

                    <label class="control-label"><?php echo ($service) ? 'Service ' : 'Class ' ?></label>
                    <div class ="controls">
                        <div class="user_photo">
                            <?php
                            if (!empty($service))
                            {
                                $photo = $service->publicAvatar;
                                $name  = $service->s_name;
                            }
                            elseif (!empty($class))
                            {
                                $photo = $class->service->publicAvatar;
                                $name  = $class->service->s_name;
                            }
                            ?>
                            <img src="<?php echo $photo ?>" alt="User photo">

                        </div>                                
                    </div>
                    <div class="control-group">
                        <div class="controls muted"><?php echo $name; ?></div>
                    </div>

                </div>
                <div class="control-group">
                    <label class="control-label">Current price</label>
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <div class="input-prepend input-append">
                        <span class="add-on"> $ </span>
                        <input id="price_item" class="span9" type="text" disabled="disabled" 
                               value="<?php echo ($service) ? $service->price : $appoint->service->price ?>">
                    </div>
                </div>
                <div class="control-group" >
                    <?php echo $form->labelEx($model, 'discount', array('class' => 'control-label')); ?>
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <div class="input-prepend input-append">
                        <span class="add-on"> % </span>
                        <input name="Hotdeal[discount]" onkeyup="calcDiscount();" 
                               type="text" id="discount_retail" class="voi-order-input ds_item"
                               value="<?php echo $model ? $model->discount : 0 ?>"/>
                    </div>
                </div>
                <div class="control-group">
                    <?php echo $form->labelEx($model, 'special_price', array('class' => 'control-label')); ?>
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <div class="input-prepend input-append">
                        <span class="add-on"> $ </span>
                        <input name="Hotdeal[special_price]" readonly="readonly" id="total_retail_text" class="span9" type="text"
                               value="<?php echo $model ? $model->special_price : 0.00 ?>">

                    </div>
                </div>
                <div class="control-group">
                    <?php $model->start_time = $model->start_time ? date('d/M/Y', $model->start_time) : '' ?>
                    <?php echo $form->labelEx($model, 'start_time', array('class' => 'control-label')); ?>
                    <div class="controls">
                        <?php
                        echo $form->textField($model, 'start_time', array(
                            'class' => 'input-xlarge datepicker'
                        ));
                        ?>
                    </div>
                </div>
                <div class="control-group">
                    <?php $model->end_time   = $model->end_time ? date('d/M/Y', $model->end_time) : '' ?>
                    <?php echo $form->labelEx($model, 'end_time', array('class' => 'control-label')); ?>
                    <div class="controls">
                        <?php
                        echo $form->textField($model, 'end_time', array(
                            'class' => 'input-xlarge datepicker'
                        ));
                        ?>
                        <?php if (Yii::app()->user->hasFlash('error1')): ?>
                            <font color="red"> <?php echo Yii::app()->user->getFlash('error1'); ?></font>
                        <?php elseif (Yii::app()->user->hasFlash('error2')): ?>
                            <font color="red"> <?php echo Yii::app()->user->getFlash('error2'); ?></font>
                        <?php endif; ?>
                    </div>
                </div>

                <div class="control-group">
                    <?php echo $form->labelEx($model, 'repeat_time', array('class' => 'control-label')) ?>
                    <div class ="controls">         
                        <?php $model->repeat_time     = $model->repeat_time ? unserialize($model->repeat_time) : '' ?>
                        <?php echo CHtml::checkBoxList('Repeat[]', $model->repeat_time, Hotdeal::getDateArray()) ?>
                        <font color="red"><?php echo $form->error($model, 'repeat_time'); ?></font>
                    </div>
                </div>
                <div class="control-group">
                    <?php echo $form->labelEx($model, 'merchant_status', array('class' => 'control-label')) ?>
                    <div class ="controls">         
                        <?php $model->merchant_status = $model->merchant_status ? $model->merchant_status : Hotdeal::MERCHANT_ACTIVE ?>
                        <?php echo $form->radioButtonList($model, 'merchant_status', Hotdeal::getArrayStatus()); ?>
                        <font color="red"><?php echo $form->error($model, 'merchant_status'); ?></font>
                    </div>
                </div>
                <div class="form-actions">
                    <button type="submit" class="btn btn-primary">Save</button>
                </div>
            </fieldset>
            <?php $this->endWidget(); ?>
        </div>
    </div><!--/span-->

</div>
<script type="text/javascript">
    function calcDiscount()
    {
        var total = <?php echo ($service) ? $service->price : $appoint->service->price ?>;
        total = total - (total * $('#discount_retail').val()) / 100;
        $('#total_retail_text').val(parseFloat(total));

    }
</script>